package br.ufrn.plugin.pewsrt.preferences;

import org.eclipse.jface.preference.*;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.IWorkbench;

import tools.IOArquivo;

import br.ufrn.plugin.pewsrt.Activator;

/**
 * This class represents a preference page that
 * is contributed to the Preferences dialog. By 
 * subclassing <samp>FieldEditorPreferencePage</samp>, we
 * can use the field support built into JFace that allows
 * us to create a page that is small and knows how to 
 * save, restore and apply itself.
 * <p>
 * This page is used to modify preferences only. They
 * are stored in the preference store that belongs to
 * the main plug-in class. That way, preferences can
 * be accessed directly via the preference store.
 */

public class PewsRTPreferencePage
	extends FieldEditorPreferencePage
	implements IWorkbenchPreferencePage {
	
	private StringFieldEditor WSDLfieldEditor; 
	private StringFieldEditor WCFfieldEditor; 

	public PewsRTPreferencePage() {
		super(GRID);
		setPreferenceStore(Activator.getDefault().getPreferenceStore());
		setDescription("PEWS-RT preferências");
	}
	
	/**
	 * Creates the field editors. Field editors are abstractions of
	 * the common GUI blocks needed to manipulate various types
	 * of preferences. Each field editor knows how to save and
	 * restore itself.
	 */
	public void createFieldEditors() {
		
/*		FileFieldEditor webBrowser = new FileFieldEditor(
				PreferenceConstants.P_PATH,
				"&Web browser:",
				true, 
				getFieldEditorParent());
		
		addField(webBrowser);*/
		
		WCFfieldEditor =  new FileFieldEditor(
				PreferenceConstants.WCF_PATH,
				"&WCF.exe:",
				true,
				getFieldEditorParent());
		
		
		addField(WCFfieldEditor);
		
		WSDLfieldEditor = new FileFieldEditor(
				PreferenceConstants.WSDL_PATH,
				"&WSDL.exe:",
				true,
				getFieldEditorParent());
		
		addField(WSDLfieldEditor);
		

	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
	 */
	public void init(IWorkbench workbench) {
	}
	
	
	public void propertyChange(PropertyChangeEvent event) {
        super.propertyChange(event);
        if (event.getProperty().equals(FieldEditor.VALUE)) {
        	System.out.println("propertyChange ");
        	System.out.println("WSDLfieldEditor " + WSDLfieldEditor.getStringValue());
        	System.out.println("WSDLfieldEditor " + WCFfieldEditor.getStringValue());
        }     
	}
	
	public boolean performOk() {
		boolean result = super.performOk();
		System.out.println("performOk ");
		IOArquivo.setPathFerramentas(WSDLfieldEditor.getStringValue(), WCFfieldEditor.getStringValue());
		System.out.println("WSDLfieldEditor " + WSDLfieldEditor.getStringValue());
    	System.out.println("WCFfieldEditor " + WCFfieldEditor.getStringValue());
		return result;
	}
	
/*	protected void performDefaults() {
		System.out.println("performOk ");
		super.performDefaults();
	}
	
	protected void checkState() {
        super.checkState();
        System.out.println("checkState");
	}
	
	public void performApply() {
		super.performApply();
		System.out.println("performApply ");
	}*/	 
}

/*LINKS
 * http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fpreferences_prefs_contribute.htm
 * http://www.eclipse.org/articles/Article-Field-Editors/field_editors.html
 * https://sites.google.com/site/eclipseplugindevelopment/9-preference-pages
 * http://www.vogella.com/articles/EclipsePreferences/article.html
 */
